package br.ufc.vv.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import br.ufc.vv.dao.DaoFactory;
import br.ufc.vv.model.Candidato;

public class CmdBuscarCandidato implements Comando{

	@Override
	public String executar(HttpServletRequest request, HttpServletResponse response) {
		
		HttpSession session = request.getSession();
		String id = request.getParameter("id");

		if (id.trim().isEmpty() || id == null) {
			return "cadastrar_candidato.jsp";
		} else {
			
			try {
				Candidato candidato = new Candidato();
				candidato = DaoFactory.findCandidato(Long.parseLong(id));
				session.setAttribute("candidato", id);
				return "cadastrar_candidato.jsp";

			} catch (Exception e) {
				e.printStackTrace();
				session.setAttribute("erro", "problema ao cadastrar candidato");
			}
		}

		return "visualizar_votacao.jsp";
	}

}
